# 定位元素id

# import  time
#
# from day2selenium import webdriver
# from day2selenium.webdriver.common.by import By
#
# # 通过id定位元素
# a = webdriver.Edge() #获取浏览器
# a.get("http://www.baidu.com")
# time.sleep(4)
# text = a.find_element(By.ID,"chat-textarea")
# # 给文本框编辑框编辑信息
# text.send_keys("python")
# text.send_keys("是什么")
# # 按钮
# button = a.find_element("id","chat-submit-button")
# button.click() #点击按钮
# time.sleep(10)

# 定位元素name

# import time
#
# from day2selenium import webdriver
# from day2selenium.webdriver.common.by import By
#
# b = webdriver.Edge()
# b.get("http://www.sogou.com")
# time.sleep(2)
#
# # 通过name定位元素
# b.find_element("name","query").send_keys("day2selenium")
# b.find_element(By.NAME,"query").send_keys("是什么")
# time.sleep(5)
#
# # 页面访问百度
# b.get("http://baidu.com")
#
# # 通过class name定位元素
# b.find_element(By.CLASS_NAME,"chat-input-textarea").send_keys("java的特点")
# b.find_element("class name","chat-input-textarea chat-input-scroll-style").send_keys("是什么")
# time.sleep(10)


# 查找多个元素

# import time
#
# from day2selenium import webdriver
# from day2selenium.webdriver.common.by import By
#
# d = webdriver.Edge() # 获取浏览器
# d.get("https://www.sogou.com")
# time.sleep(2) # 等待页面加载
#
# # 定位所有a标签
# aelments = d.find_elements(By.TAG_NAME,"a")
# print(aelments) # WebElement
# # for ae in aelments: # ae代表查询出的单个元素信息
#     # print(ae.get_dom_attribute("href"))
#     # print(ae.text)  # a标签的文本  <a>百度</a>
#
# imgs = d.find_elements("tag name","img")
# for img in imgs:
#     print(img.get_dom_attribute("src"))


# 针对a标签的定位,通过查询a标签的文本进行定位

# import time
#
# from day2selenium import webdriver
# from day2selenium.webdriver.common.by import By
#
# c = webdriver.Edge() # 获取浏览器
# c.get("https://www.baidu.com")
# time.sleep(2) # 等待页面加载
#
# # 完全匹配定位
# a = c.find_element(By.LINK_TEXT,"网盘")
# print(a.text)
#
# # 部分匹配定位
# a1 = c.find_element("PARTIAL_LINK_TEXT","40米")
# print(a1.text)
# print(a1.get_dom_attribute("href"))

# 选择器定位

# import time
#
# from day2selenium import webdriver
# from day2selenium.webdriver.common.by import By
#
# d = webdriver.Edge() # 获取浏览器
# d.get("https://www.sogou.com")
# time.sleep(2)
#
# d.find_element(By.CSS_SELECTOR,"#query").send_keys("选择器")
# d.find_element(By.CSS_SELECTOR,".sec-input").send_keys("有哪些")
# a = d.find_element(By.CSS_SELECTOR,"div").get_dom_attribute("class")
# print(a)
# b = d.find_element(By.CSS_SELECTOR,"[type ='text']").get_dom_attribute("name")
# print(b)
# c = d.find_element(By.CSS_SELECTOR,"#hanyu").get_dom_attribute("href")
# print(c)

# xpath

# import time
#
# from day2selenium import webdriver
# from day2selenium.webdriver.common.by import By
#
# d = webdriver.Edge() # 获取浏览器
# d.get("https://www.sogou.com")
# time.sleep(4)
#
# a = d.find_element(By.XPATH,"/html/body/div/div[2]/div[4]/form/span[1]/input")
# a.send_keys("xpath")
#
# b = d.find_element("xpath","//*[@id='query']")
# b.send_keys("相对路径")
#
# c = d.find_element(By.XPATH,"//*[contains(text(),'药品医疗器械')]")
# print(c.get_dom_attribute("class"))
#
# e = d.find_element("xpath","//*[@id='sf']/span[1]")
# print(e.get_dom_attribute("name"))

# 浏览器操作

import time

from selenium import webdriver
from selenium.webdriver.common.by import By

l = webdriver.Edge()
l.get("https://www.sogou.com")
time.sleep(2)
l.get("https://www.baidu.com")
time.sleep(2)
l.get("https://www.douyin.com")
time.sleep(2)
l.back()
time.sleep(2)
l.forward()
time.sleep(2)
l.maximize_window()
time.sleep(2)
l.minimize_window()
time.sleep(2)
l.set_window_size(500,500)
time.sleep(2)
l.close()
l.quit()
